/*
 * @Author: chen haoxuan
 * @Date: 2021-05-24 22:04:19
 * @LastEditTime: 2021-05-24 22:27:28
 */
#include<iostream>
using namespace std;
class Complex
{
  public:
    Complex(){real=0;imag=0;}
    Complex(double r,double i):real(r),imag(i){}
    friend ostream& operator <<(ostream& ,Complex &);
    friend Complex operator+(int,Complex &);
    friend Complex operator+(Complex &,int);
  private:
    double real;
    double imag;  
};
ostream& operator <<(ostream& output,Complex &c)  // 重载输出流运算符
{
    output<<"("<<c.real<<"+"<<c.imag<<"i)";
    return output;
}
Complex operator+(int i,Complex &c) // 重载 + 前 实数 后 复数
{
    return Complex(i+c.real,c.imag);
}
Complex operator+(Complex &c,int i)
{
    return Complex(c.real,i+c.imag);
}
int main()
{
    Complex c1(3,4),c2,c3;
    c2=1+c1;cout<<c2<<endl; // 4+4i
    c3=c1+4;cout<<c3<<endl; // 3+8i
    system("pause");
    return 0;
}